/**
* -------------------------------------------------------------
* @author  cl
* @date: 2021-12-28 17:28:05
* @description: 上传文件bind表 serviceImpl
* -------------------------------------------------------------
* @version 1.0.0
* @Copyright (c) 中科星图-版权所有
*/

package com.geovis.boot.service.demo.file.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.boot.service.demo.file.entity.FileBind;
import com.geovis.boot.service.demo.file.mapper.FileBindMapper;
import com.geovis.boot.service.demo.file.service.IFileBindService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 上传文件bind表接口实现
 * @author cl
 */
@Slf4j
@Service
@Transactional
public class IFileBindServiceImpl extends ServiceImpl<FileBindMapper, FileBind> implements IFileBindService {

    @Autowired
    private FileBindMapper fileBindMapper;

    @Override
    public FileBind getById(String id) {

       return fileBindMapper.selectById(id);
    }

    @Override
    public List<FileBind> getList(String updateBy) {
        QueryWrapper<FileBind> wrapper = new QueryWrapper<>();
        wrapper.select("updateBy", updateBy);
        List<FileBind> fileBinds = fileBindMapper.selectList(wrapper);
        return fileBinds;
    }

    @Override
    public IPage getByParam(Long pageNum, Long pageSize, String uri, String path) {
        QueryWrapper<FileBind> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(uri) ){
            wrapper.eq("uri",uri);
        }
        if(!StringUtils.isEmpty(path) ){
            wrapper.eq("path",path);
        }
        Page<FileBind> page = new Page<>(pageNum,pageSize);
        IPage<FileBind> iPage = fileBindMapper.selectPage(page, wrapper);
        return iPage;
    }

    @Override
    public boolean saveOrUpdate(FileBind fileBind) {
        return saveOrUpdate(fileBind);
    }

    @Override
    public boolean removeById(String id) {
        return removeById(id);
    }

    @Override
    public boolean batchRemoveByIds(String[] ids) {
        for(String id : ids){
            removeById(id);
        }
        return true;
    }

    @Override
    public FileBind selectFileBinds(String id) {
        return fileBindMapper.selectFileBinds(id);
    }
}
